using DG.Tweening;
using UnityEngine;
using EchoFramework;

/// <summary>
/// 游戏运行时界面
/// </summary>
public class GameView : UIViewBase
{
    private EchoButton restartBtn;
    private EchoButton homeBtn;
    private EchoButton settingBtn;

    public override void OnAwake()
    {
        base.OnAwake();
        restartBtn = prefabBinder.Find("ReStartBtn").GetComponent<EchoButton>();
        restartBtn.onClick.AddListener(OnClickRestartBtn);
        homeBtn = prefabBinder.Find("HomeBtn").GetComponent<EchoButton>();
        homeBtn.onClick.AddListener(OnClickHomeBtn);
        settingBtn = prefabBinder.Find("SettingBtn").GetComponent<EchoButton>();
        settingBtn.onClick.AddListener(OnClickSettingBtn);
    }

    public override void OnStart(params object[] objs)
    {
        base.OnStart(objs);
        AudioManager.Instance.PlayerGameBGM();
    }

    /// <summary>
    /// 点击重开按钮
    /// </summary>
    private void OnClickRestartBtn()
    {
        DOTween.KillAll();
        MapLogicModule.Instance.LoadMapLevel(MapLogicModule.Instance.Level);
    }

    /// <summary>
    /// 点击首页按钮
    /// </summary>
    private void OnClickHomeBtn()
    {
        CloseWindow();
        UIViewManager.Instance.OpenWindow(UIViewID.MainMenuView);
    }

    /// <summary>
    /// 点击设置按钮
    /// </summary>
    private void OnClickSettingBtn()
    {
        UIViewManager.Instance.OpenWindow(UIViewID.SettingView);
    }

    public override void OnClose()
    {
        base.OnClose();
        AudioManager.Instance.PlayerMainMenuBGM();
        GameEntry.Instance.GameEnd();
    }
}